from django.shortcuts import render

from .models import BookInfo, AreaInfo
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect


# Create your views here.


def index(request):
    booklist = BookInfo.objects.all()
    # template = loader.get_template("hero_books/index.html")
    # return response.HttpResponse(template.render({'booklist': booklist}))
    return render(request, "hero_books/index.html", {'booklist': booklist})


def detail(request, id):
    book = BookInfo.objects.get(pk=id)
    book.heroinfo_set.all()
    # template1 = loader.get_template("hero_books/detail.html")
    # return response.HttpResponse(template1.render({'book': book}))
    return render(request, "hero_books/detail.html", {'book': book})


def area(request):
    area = AreaInfo.objects.get(pk=1)
    return render(request, "hero_books/area.html", {"area": area})


def show_params(requset, bread, bid, food):
    print(food)
    print(bid)
    print(bread)
    return render(requset, "hero_books/showparams.html", {"bid": bid, "bread": bread})


def url_reverse(request, year):
    return render(request, "hero_books/reverse.html", {"year": year})


def year(request, year):
    return render(request, "hero_books/year.html", {"year": year})
